package business_opportunity

import (
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-api/http_server/backend_controller"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/common/errcode"
	dto "git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/dto/business_opportunity"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/utils"
	"git.mycaigou.com/gfyx/micro-gfyx-api/service/business_opportunity/strategic_monitor"
	"github.com/gin-gonic/gin"
)

type StrategicMonitorGroupController struct {
	backend_controller.BackendBaseController
	strategicMonitorService strategic_monitor.StrategicMonitorServiceIface
}

func NewStrategicMonitorGroupController(
	strategicMonitorService strategic_monitor.StrategicMonitorServiceIface,
) *StrategicMonitorGroupController {
	return &StrategicMonitorGroupController{strategicMonitorService: strategicMonitorService}
}

func (c *StrategicMonitorGroupController) RegisterRouter(g *gin.RouterGroup) {
	g.POST("business_opportunity/strategic-monitor/bid-list", c.bidList)
	g.GET("business_opportunity/strategic-monitor/bid-detail", c.bidDetail)
	g.POST("business_opportunity/strategic-monitor/bid-audit", c.bidAudit)

	g.POST("business_opportunity/strategic-monitor/company-list", c.companyList)
	g.POST("business_opportunity/strategic-monitor/company-audit", c.companyAudit)
	g.POST("business_opportunity/strategic-monitor/company-add", c.companyAdd)
	g.GET("business_opportunity/strategic-monitor/company-detail", c.companyDetail)

	g.POST("business_opportunity/strategic-monitor/industry-list", c.industryList)
	g.POST("business_opportunity/strategic-monitor/industry-audit", c.industryAudit)
	g.POST("business_opportunity/strategic-monitor/industry-add", c.industryAdd)

	g.GET("business_opportunity/strategic-monitor/company-bid-list", c.companyBidList)
	g.POST("business_opportunity/strategic-monitor/company-bid-delete", c.companyBidDelete)
	g.GET("business_opportunity/strategic-monitor/company-cooperate-list", c.companyCooperateList)
	g.POST("business_opportunity/strategic-monitor/company-cooperate-delete", c.companyCooperateDelete)
	g.POST("business_opportunity/strategic-monitor/company-import", c.companyImport)
}

func (c *StrategicMonitorGroupController) bidList(ctx *gin.Context) {
	request := &dto.GetStrategicBidListRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	if request.Page == 0 {
		request.Page = 1
	}
	if request.PageSize == 0 {
		request.PageSize = 20
	}

	response, err := c.strategicMonitorService.GetStrategicBidList(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) bidDetail(ctx *gin.Context) {
	request := &dto.GetStrategicBidDetailRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}

	response, err := c.strategicMonitorService.GetStrategicBidDetail(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) bidAudit(ctx *gin.Context) {
	request := &dto.AuditStrategicBidRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}

	response, err := c.strategicMonitorService.AuditStrategicBid(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyList(ctx *gin.Context) {
	request := &dto.GetBidCompanyListRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	if request.Page == 0 {
		request.Page = 1
	}
	if request.PageSize == 0 {
		request.PageSize = 20
	}

	response, err := c.strategicMonitorService.GetBidCompanyList(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyAudit(ctx *gin.Context) {
	request := &dto.AuditBidCompanyRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.AuditBidCompany(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyAdd(ctx *gin.Context) {
	request := &dto.AddBidCompanyRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.AddBidCompany(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyDetail(ctx *gin.Context) {
	request := &dto.GetBidCompanyDetailRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.GetBidCompanyDetail(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) industryList(ctx *gin.Context) {
	request := &dto.GetIndustryListRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	if request.Page == 0 {
		request.Page = 1
	}
	if request.PageSize == 0 {
		request.PageSize = 20
	}

	response, err := c.strategicMonitorService.GetIndustryList(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) industryAudit(ctx *gin.Context) {
	request := &dto.AuditIndustryRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.AuditIndustry(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) industryAdd(ctx *gin.Context) {
	request := &dto.AddIndustryRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.AddIndustry(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyBidList(ctx *gin.Context) {
	request := &dto.GetCompanyBidListRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	if request.Page == 0 {
		request.Page = 1
	}
	if request.PageSize == 0 {
		request.PageSize = 20
	}

	response, err := c.strategicMonitorService.GetCompanyBidList(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyBidDelete(ctx *gin.Context) {
	request := &dto.DeleteBidAuditRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}

	response, err := c.strategicMonitorService.DeleteBidCompany(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyCooperateList(ctx *gin.Context) {
	request := &dto.GetCompanyCooperateListRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	if request.Page == 0 {
		request.Page = 1
	}
	if request.PageSize == 0 {
		request.PageSize = 20
	}

	response, err := c.strategicMonitorService.GetCompanyCooperateList(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyCooperateDelete(ctx *gin.Context) {
	request := &dto.DeleteCooperateCompanyRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.DeleteCooperateCompany(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) companyImport(ctx *gin.Context) {
	request := &dto.ImportCompanyBidRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, utils.GetValidateErr(request, err))
		return
	}
	response, err := c.strategicMonitorService.ImportCompanyBid(ctx, request)
	if err != nil {
		grpcErr := rpc_client.GetGrpcError(err)
		c.Fail(ctx, grpcErr.GetCode(), grpcErr.GetMessage())
		return
	}

	c.Success(ctx, response)
}

func (c *StrategicMonitorGroupController) empty(ctx *gin.Context) {
	c.Success(ctx, "i am empty")
}
